package com.cskaoyan.service.impl;

import com.cskaoyan.bean.BaseData;
import com.cskaoyan.bean.bo.LogParam;
import com.cskaoyan.bean.pojo.MallLog;
import com.cskaoyan.bean.pojo.MallLogExample;
import com.cskaoyan.mapper.MallLogMapper;
import com.cskaoyan.service.LogService;
import com.cskaoyan.util.MyPageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: Fengyi
 * @description: Log实现类
 * @time: 2021/7/9 20:20
 */
@Service
public class LogServiceImpl implements LogService {

    @Autowired
    MallLogMapper mallLogMapper;

    @Override
    public BaseData<MallLog> queryLog(LogParam param) {


        MyPageHelper.startPage(param);

        MallLogExample mallLogExample = new MallLogExample();
        MallLogExample.Criteria criteria = mallLogExample.createCriteria();
        criteria.andDeletedEqualTo(false);
        if (param.getName() != null) {
            criteria.andAdminLike("%" + param.getName() + "%");
        }

        mallLogExample.setOrderByClause(param.getSort() + " " + param.getOrder());
        List<MallLog> logs = mallLogMapper.selectByExample(mallLogExample);
        long total = mallLogMapper.countByExample(mallLogExample);

        return BaseData.ok(logs, total);
    }

    @Override
    public void insertLog(MallLog mallLog) {
        mallLogMapper.insertSelective(mallLog);
    }
}
